<template>
  <div class="container">
    <!-- 弹窗 -->
    <el-dialog title="题目预览" :visible="showDialog" width="900px" @close="btnCancel">
      <el-row>
        <el-col :span="6" style="padding: 10px 0">【题型】：{{ formatEmployment(list.questionType) }}</el-col>
        <el-col :span="6" style="padding: 10px 0">【编号】：{{ list.id }}</el-col>
        <el-col :span="6" style="padding: 10px 0">【难度】：{{ difficultylist(list.difficulty) }}</el-col>
        <el-col :span="6" style="padding: 10px 0">【标签】：{{ list.tags }}</el-col>
        <el-col :span="6" style="padding: 10px 0">【学科】：{{ list.subjectName }}</el-col>
        <el-col :span="6" style="padding: 10px 0">【目录】：{{ list.directoryName }}</el-col>
        <el-col :span="6" style="padding: 10px 0">【方向】：{{ list.direction }}</el-col>
      </el-row>
      <hr />
      <el-row>
        <el-col :span="24">【题干】：</el-col>
        <el-col :span="24" style="margin: 4px 0;color: blue;">
          <div v-html="list.question"></div>
        </el-col>
        <el-col :span="24" style="padding-bottom: 8px ">
          {{
          formatEmployment(list.questionType)
          }}
          选项：（以下选中的选项为正确答案）
        </el-col>
        <el-col :span="24" style="padding-bottom: 8px;" v-for="item in list.options" :key="item.id">
          <el-radio v-if="!item.title == ''" :value="item.isRight" :label="1">
            {{
            item.title
            }}
          </el-radio>
        </el-col>
      </el-row>
      <hr />
      <el-row>
        <el-col :span="24" style="margin: 14px 0">
          【参考答案】：
          <el-button type="success" @click="video = true">视频答案预览</el-button>
        </el-col>
        <el-col :span="24">
          <video width="320" height="240" controls v-if="video" autoplay>
            <source :src="list.videoURL" type="video/mp4" />
            <source :src="list.videoURL" type="video/ogg" />
            <source :src="list.videoURL" type="video/webm" />您的浏览器不支持 video 标签。
          </video>
        </el-col>
      </el-row>
      <hr />
      <el-row>
        <el-col :span="24" style="margin: 14px 0">【答案解析】：：{{ list.remarks }}</el-col>
      </el-row>
      <hr />
      <el-row>
        <el-col :span="24" style="margin: 14px 0">【题目备注】：{{ list.remarks }}</el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="btnCancel()">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import { questionType, difficulty } from '@/api/hmmm/constants.js' // 通用常量
export default {
  data () {
    return {
      // 视频显示与否
      video: true
    }
  },
  props: {
    list: {
      type: [Object, String, Number],
      required: true
    },
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 枚举题型
    formatEmployment (id) {
      // 要去找 1所对应的值
      const obj = questionType.find(item => item.value === id)
      return obj ? obj.label : '未知'
    },
    // 枚举难度
    difficultylist (id) {
      const obj = difficulty.find(item => item.value === id)
      return obj ? obj.label : '未知'
    },
    // 点击关闭关闭弹窗
    btnCancel () {
      this.$emit('update:showDialog', false)
      this.video = false // 关闭视频
    }
  }
}
</script>

<style scoped lang="scss"></style>
